package com.serivceImpl;

import com.javabean.Users;
import com.mapper.UsersMapper;
import com.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UsersServiceImpl implements UsersService {
    @Autowired
    UsersMapper usersMapper;
    @Override
    public Users login(String username, String password) {
        return usersMapper.selectByUsernameAndPassword(username,password);
    }

    @Override
    public List<Users> findAll() {
        return usersMapper.selectAll();
    }

    @Override
    public void add(Users users,int roleId) {
        usersMapper.insertUsers(users);
        usersMapper.insertU_R(users.getId(),roleId);
    }

    @Override
    public void delete(int id) {
        usersMapper.deleteById(id);
    }

    @Override
    public Users findById(int id) {
        return usersMapper.selectById(id);
    }

    @Override
    public void edit(Users users,int roleId) {
        usersMapper.updateUsers(users);
        usersMapper.updateU_R(users.getId(),roleId);
    }

}
